
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5+10;
inline int read(){
    int w=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        w=w*10+ch-'0';
        ch=getchar();
    }
    return w*f;
}
int T,N,Ans=0;
int A[MAXN],Cl[MAXN];
void did(){
    int NUM=0;
    bool check=false;
    for(int i=N;i>=2;i--){
        check=true;
        for(int j=i-1;j>=1;j--){
            if(Cl[j]==Cl[i]&&check&&A[j]==A[i]&&i!=j){
                check=true; NUM+=A[j];
            }
        }
    }
    Ans=max(Ans,NUM); 
    return;
}
void dfs(int dep){
    if(dep==N+1){did(); return;}
    Cl[dep]=1; dfs(dep+1);
    Cl[dep]=2; dfs(dep+1);
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T--){
        Ans=0;
        N=read();
        for(int i=1;i<=N;i++){A[i]=read();}
        dfs(1);
        printf("%d\n",Ans);
    }
    return 0;
}